import React from 'react'

import BaseModelNew from './BaseModelNew'
import Config from '../config'
import HeartConstants from '../common/HeartConstants'
import ResponseConstants from '../common/ResponseConstants'

export default class HeartModel extends BaseModelNew {
  constructor(props) {
    super(props)

    this.sendRequestLoveUsers = this.sendRequestLoveUsers.bind(this)
    this.sendRequestRecommendedLoveUsers = this.sendRequestRecommendedLoveUsers.bind(this)
    this.searchLoveList = this.searchLoveList.bind(this)
    this.sendRequestSelfData = this.sendRequestSelfData.bind(this)
    this.sendUpdateSelfData = this.sendUpdateSelfData.bind(this)
    this.sendCreateSeldData = this.sendCreateSeldData.bind(this)
    this.sendRequestOtherData = this.sendRequestOtherData.bind(this)
    this.sendLikeUser = this.sendLikeUser.bind(this)
    this.requestLoveChatOneList = this.requestLoveChatOneList.bind(this)
    this.sendLoveChat = this.sendLoveChat.bind(this)
    this.sendRequestQuestionList = this.sendRequestQuestionList.bind(this)
    this.sendAskQuestion = this.sendAskQuestion.bind(this)
    this.sendRequestZJList = this.sendRequestZJList.bind(this)
    this.createConsult = this.createConsult.bind(this)
    this.requestExpertData = this.requestExpertData.bind(this)
    this.volunteerSubmit = this.volunteerSubmit.bind(this)
    this.requestEapList = this.requestEapList.bind(this)
    this.requestZJMsgCount = this.requestZJMsgCount.bind(this)
    this.requestSecretChatOneList = this.requestSecretChatOneList.bind(this)
    this.requestZJMsgList = this.requestZJMsgList.bind(this)
    this.sendSecretChat = this.sendSecretChat.bind(this)
    this.requestVolunteerPostContent = this.requestVolunteerPostContent.bind(this)
    this.requestVolunteerPostList = this.requestVolunteerPostList.bind(this)
    this.sendDeleteSelfData = this.sendDeleteSelfData.bind(this)
    this.requestEndList = this.requestEndList.bind(this)
    this.requestEndListContent = this.requestEndListContent.bind(this)
    this.requestTextURL = this.requestTextURL.bind(this)
    this.putMedia = this.putMedia.bind(this)
    this.getMedia = this.getMedia.bind(this)
    this.getMatchingSelfeDate = this.getMatchingSelfeDate.bind(this)
    this.upDateMatchingSelfeDate = this.upDateMatchingSelfeDate.bind(this)
    this.requestExpertsToday = this.requestExpertsToday.bind(this)
    this.requestReportLover = this.requestReportLover.bind(this)
    this.requestBlackLover = this.requestBlackLover.bind(this);
  }

  setup(dataManager) {
    super.setup(dataManager)
    for (var bigType in HeartConstants.totalData) {
      if (bigType == 'self_intro' || bigType == 'tags_list' || bigType == 'image_urls') {
        HeartConstants.allDataForeach[bigType] = HeartConstants.totalData[bigType]
      } else {
        for (var smallType in HeartConstants.totalData[bigType]) {
          HeartConstants.allDataForeach[smallType] = HeartConstants.totalData[bigType][smallType]
        }
      }
    }
  }

  requestVolunteerPostList(data, callback) {}

  requestVolunteerPostContent(data, callback) {}

  //爱情事 相亲列表
  //http://118.89.111.124:8080/lovers?page=1&page_size=5&sort_id=1
  //sort_id 排序方式，1最新，2点赞
  sendRequestLoveUsers(data, callback) {
    var url = Config.serverUrl + '/lovers?page=' + data.page + '&page_size=10&sort_id=' + data.sort_id
    this.sendGet(url, callback)
  }

  //http://118.89.111.124:8080/dqapp/lovers/recommended?page=1&page_size=5
  sendRequestRecommendedLoveUsers(data, callback) {
    var url = Config.serverUrl + '/lovers/recommended?page=' + data.page + '&page_size=10'
    this.sendGet(url, callback)
  }

  //http://118.89.111.124:8080/lovers/searched?age=1&education=3&gender=2&height=1&
  //income=2&job_status=3&marital_status=2&page=1&page_size=5&weight=1
  searchLoveList(data, callback) {
    var url = Config.serverUrl + '/lovers/search?page=' + data.page + '&page_size=10'
    this.sendPost(url, JSON.stringify(data), callback)
  }

  //http://118.89.111.124:8080/lovers/owned
  //请求自己数据
  sendRequestSelfData(data, callback) {
    var url = Config.serverUrl + '/lovers/owned'
    this.sendGet(url, callback)
  }

  // http://118.89.111.124:8080/lovers/
  //发布相亲信息
  sendCreateSeldData(data, callback) {
    console.log(data)
    this.sendPost(Config.serverUrl + '/lovers', JSON.stringify(data), callback)
  }
  // /dqapp/lovers/matching
  // 获取用户择偶标准
  getMatchingSelfeDate(data, callback) {
    this.sendGet(Config.serverUrl + '/lovers/matching', callback)
  }

  // /dqapp/lovers/matching/{lover_id}
  //更新用户择偶标准
  upDateMatchingSelfeDate(data, callback) {
    this.sendPatchNew(Config.serverUrl + '/lovers/matching/' + data.lover_id, JSON.stringify(data), callback)
  }

  // http://118.89.111.124:8080/lovers/{lover_id}
  //更新自己信息
  sendUpdateSelfData(data, callback) {
    this.sendPatchGetJasn(Config.serverUrl + '/lovers/' + data.lover_id, JSON.stringify(data), callback)
  }

  //删除自己信息
  sendDeleteSelfData(data, callback) {
    this.sendPatchGetJasn(Config.serverUrl + '/lovers/owned', JSON.stringify(data), callback)
  }

  //http://118.89.111.124:8080/dqapp/lovers/11
  //获取其他相亲者信息
  sendRequestOtherData(data, callback) {
    var url = Config.serverUrl + '/lovers/' + data.lover_id
    this.sendGet(url, callback)
  }

  //http://118.89.111.124:8080/dqapp/lovers/1/like
  //点赞
  sendLikeUser(data, callback) {
    var url = Config.serverUrl + '/lovers/' + data.lover_id + '/like'
    this.sendPut(url, callback)
  }
  //
  requestReportLover(data,callback){
    var url = Config.serverUrl + '/lovers/report_lover?lover_id=' + data.lover_id + '&reason='+data.reason+'&type='+data.type;
    this.sendPut(url, callback)
  }
  // PUT /dqapp/lovers/set_blacklist
  requestBlackLover(data,callback){
    var url = Config.serverUrl + '/lovers/set_blacklist?lover_id=' + data.lover_id + '&state='+data.state;
    this.sendPut(url, callback)
  }
  //爱情事 某个人的所有私聊记录
  //http://dqtest.bestplus.me/dqapp/msgs?page=1&page_size=5&target_id=1&type=1
  requestLoveChatOneList(actionData, callback) {
    var url =
      Config.serverUrl +
      '/msgs?page=' +
      actionData.page +
      '&page_size=10&target_id=' +
      actionData.target_id +
      '&type=' +
      actionData.type
    this.sendGet(url, callback, ResponseConstants.responseType_json, actionData.forceRequest)
  }

  //发送爱情事的私聊
  //http://dqtest.bestplus.me/dqapp/msgs
  sendLoveChat(actionData, callback) {
    var sendData = {
      content: actionData.content,
      target_id: actionData.target_id,
      type: actionData.type
    }
    this.sendPost(Config.serverUrl + '/msgs', JSON.stringify(sendData), callback)
  }

  //爱的困惑
  //http://118.89.111.124:8080/love_questions?page=1&page_size=5
  sendRequestQuestionList(data, callback) {
    var url = Config.serverUrl + '/love_questions?page=' + data.page + '&page_size=10'
    this.sendGet(url, callback)
  }

  //http://118.89.111.124:8080/love_questions
  //发表疑问
  sendAskQuestion(data, callback) {
    var url = Config.serverUrl + '/love_questions'
    this.sendPostGetJson(url, JSON.stringify(data), callback)
  }

  sendRequestZJList(data, callback) {
    var url = Config.serverUrl + '/experts?page=' + data.page + '&page_size=' + data.page_size + '&sort_id=1'
    if (data.recommended) {
      url = Config.serverUrl + '/experts/recommended?page=' + data.page + '&page_size=' + data.page_size
    }
    this.sendGet(url, callback)
  }

  //预约咨询
  createConsult(data, callback) {
    var sendData = {
      contact_way: data.contact_way,
      name: data.name,
      question: data.question
    }
    this.sendPost(
      Config.serverUrl + '/experts/' + data.expert_id + '/consultations',
      JSON.stringify(sendData),
      callback
    )
  }
  //获取今日专家
  requestExpertsToday(data, callback) {
    var url = Config.serverUrl + '/experts/today'
    this.sendGet(url, callback)
  }
  requestExpertData(data, callback) {
    var url = Config.serverUrl + '/experts/' + data.expert_id
    this.sendGet(url, callback)
  }

  volunteerSubmit(data, callback) {
    var sendData = {
      contact_way: data.contact_way,
      name: data.name,
      gender: data.gender,
      minzu: data.minzu,
      department: data.department,
      marital_status: data.marital_status,
      service_type: data.service_type,
      reason: data.reason,
      qualification: data.qualification
    }
    this.sendPost(Config.serverUrl + '/volunteers', JSON.stringify(sendData), callback)
  }

  // 活动类型为3为eap活动
  requestEapList(actionData, callback) {
    let home_page = 0
    if (actionData.home_page != undefined) {
      home_page = actionData.home_page
    }
    var url =
      Config.serverUrl +
      '/activities?type=3&page=' +
      actionData.page +
      '&page_size=' +
      actionData.page_size +
      '&tag=' +
      actionData.tag +
      '&home_page=' +
      home_page
    if (actionData.show_last_days) {
      url += '&show_last_days=' + actionData.show_last_days
    }
    this.sendGet(url, callback)
  }

  requestZJMsgCount(data, callback) {
    var url = Config.serverUrl + '/counts/unread_msguser?type=' + data.type
    this.sendGet(url, callback)
  }

  //秘密留言 某个人的所有私聊记录
  //http://dqtest.bestplus.me/dqapp/msgs?page=1&page_size=5&target_id=1&type=1
  requestSecretChatOneList(actionData, callback) {
    var url =
      Config.serverUrl +
      '/msgs?page=' +
      actionData.page +
      '&page_size=10&target_id=' +
      actionData.target_id +
      '&type=' +
      actionData.type
    this.sendGet(url, callback, ResponseConstants.responseType_json, actionData.forceRequest)
  }

  //发送私聊
  //http://dqtest.bestplus.me/dqapp/msgs
  sendSecretChat(actionData, callback) {
    var sendData = {
      content: actionData.content,
      target_id: actionData.target_id,
      type: actionData.type
    }
    this.sendPost(Config.serverUrl + '/msgs', JSON.stringify(sendData), callback)
  }

  requestZJMsgList(data, callback) {
    var url = Config.serverUrl + '/msgusers?page=' + data.page + '&page_size=' + data.page_size + '&type=' + data.type
    this.sendGet(url, callback)
  }

  requestEndList(data, callback) {
    var url = Config.serverUrl + '/boards/' + data.board_id + '/posts?page=' + data.page + '&page_size=10&sort_id=1'
    this.sendGet(url, callback)
  }

  requestEndListContent(data, callback) {
    var url = Config.serverUrl + '/boards/' + data.board_id + '/posts/' + data.post_id
    this.sendGet(url, callback)
  }

  requestTextURL(data, callback) {
    var url = Config.serverUrl + '/surveys'
    this.sendPost(url, JSON.stringify({}), callback)
  }

  // 更新相亲者照片和视频
  putMedia(data, callback) {
    var url = Config.serverUrl + '/lovers/put_media?lover_id=' + data.lover_id
    this.sendPutPostJson(url, JSON.stringify(data), callback)
  }

  // 获得相亲者照片和视频列表
  getMedia(data, callback) {
    var url = Config.serverUrl + '/lovers/get_media'
    this.sendGet(url, callback)
  }
}
